import 'package:flutter/material.dart';

class DotFont extends StatefulWidget {
  DotFont({Key? key}) : super(key: key);

  @override
  State<DotFont> createState() => _DotFontState();
}

class _DotFontState extends State<DotFont> with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: FontPainter(),
    );
  }
}

class FontPainter extends CustomPainter {
  final dao = [
    0x0100,
    0x0200,
    0x1FF0,
    0x1010,
    0x1210,
    0x1150,
    0x1020,
    0x1000,
    0x1FFC,
    0x0204,
    0x2224,
    0x2224,
    0x3FE4,
    0x0004,
    0x0028,
    0x0010
  ];
  @override
  void paint(Canvas canvas, Size size) {
    final dotCount = 16;
    final fontSize = 100.0;
    var radius = fontSize / dotCount;
    var startPos =
        Offset(size.width / 2 - fontSize, size.height / 2 - fontSize);
    var paint = Paint()..color = Colors.blue[600]!;
    for (int i = 0; i < dotCount; ++i) {
      var position = startPos + Offset(0.0, radius * i * 2);
      for (int j = 0; j < dotCount; ++j) {
        var paintPos = Offset(startPos.dx + radius * j * 2, position.dy);
        // 判断第 i 行第几位不为0，不为0则绘制，否则不绘制
        if ((dao[i] & ((2 << dotCount - j - 1))) != 0) {
          canvas.drawCircle(paintPos, radius, paint);
        }
      }
    }
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
